/***************************************************************************
 *   This is a part of the NextCAD Web APP.                                *
 *   Copyright (C) AMCAX, All rights reserved.                             *
 ***************************************************************************/

import { CSCircle, CSLine, css2dInputLable } from '@amcax/base';
import { AnnotationType, EllipseState } from '../dimension/types';

export enum State {
  NONE,
  DRAWONE,
  DRAWTWO,
  INPUT,
  FINISH,
}
export type MouseState =
  | State.NONE
  | State.DRAWONE
  | State.DRAWTWO
  | State.FINISH
  | State.INPUT;

export type MousePoint = {
  x: number;
  y: number;
};

export interface TrackingData {
  circle: CSCircle;
  rLine: CSLine;
  rLabel: css2dInputLable;
}

export const P_Line2 = [
  'Point-Line',
  'Line-Point',
  'Line-Ellipse',
  'Ellipse-Line',
];

export const P_Line = [
  ...P_Line2,
  'Line-Circle',
  'Circle-Line',
  'Line-ArcOfCircle',
  'ArcOfCircle-Line',
  'Line-Ellipse',
  'Ellipse-Line',
];

export const C_Curve = [
  'Circle-Circle',
  'Circle-ArcOfCircle',
  'ArcOfCircle-Circle',
  'Circle-Ellipse',
  'Ellipse-Circle',
  'ArcOfCircle-ArcOfCircle',
  'ArcOfCircle-Ellipse',
  'Ellipse-ArcOfCircle',
  'Ellipse-Ellipse',
];

export const P_Point = [
  'Point-Point',
  'Point-Circle',
  'Circle-Point',
  'Point-ArcOfCircle',
  'ArcOfCircle-Point',
  'Point-Ellipse',
  'Ellipse-Point',
  ...C_Curve,
];
export const CURVE = ['Circle', 'ArcOfCircle', 'Ellipse'];
export const SET_RIGHT_MENU = 'SetRightMenu';

const horizontal = (action) => ({
  name: '水平方向',
  id: 'horizontal',
  params: { type: AnnotationType.DistanceXAnno },
  action,
});

const vertical = (action) => ({
  name: '垂直方向',
  id: 'vertical',
  params: { type: AnnotationType.DistanceYAnno },
  action,
});

const lineDir = (action) => ({
  name: '长度',
  id: 'line',
  params: {
    type: AnnotationType.DistanceAnno,
  },
  action,
});
const radius = (action) => ({
  name: '半径',
  id: 'radius',
  params: { type: AnnotationType.RadiusAnno, curve: 'radius' },
  action,
});
const diameter = (action) => ({
  name: '直径',
  id: 'diameter',
  params: { type: AnnotationType.RadiusAnno, curve: 'diameter' },
  action,
});
const majorAxis = (action) => ({
  name: '长轴',
  id: 'majorAxis',
  params: { type: AnnotationType.MajorRadiusAnno, curve: EllipseState.major },
  action,
});
const minorAxis = (action) => ({
  name: '短轴',
  id: 'minorAxis',
  params: { type: AnnotationType.MinorRadiusAnno, curve: EllipseState.minor },
  action,
});

export const MENU_ITEMS = (action) => {
  return {
    [AnnotationType.DimensionAnno]: [horizontal(action), vertical(action)],
    [AnnotationType.DistanceAnno]: [horizontal(action), vertical(action)],
    [AnnotationType.DistanceXAnno]: [vertical(action), lineDir(action)],
    [AnnotationType.DistanceYAnno]: [horizontal(action), lineDir(action)],
    [AnnotationType.RadiusAnno]: [radius(action), diameter(action)],
    [AnnotationType.MajorRadiusAnno]: [minorAxis(action)],
    [AnnotationType.MinorRadiusAnno]: [majorAxis(action)],
  };
};
